Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the problem of when cancel Unhandled Exception: Instance of 'QueueCancelledException' #17

Closed
wants to merge 1 commit into from

Conversation

zeqinjie
Copy link

@zeqinjie zeqinjie commented Apr 27, 2023

import 'package:queue/queue.dart';

Future<void> main() async {
  final queue = Queue(delay: const Duration(milliseconds: 100));

  Future asyncMessage(String message) async {
    print(message);
  }

  unawaited(queue
      .add(() async {
        await asyncMessage("Message 1");
      })
      .then((result) => print("Message 1 complete"))
      .catchError((e) => print("Message 1 error: $e")));

  unawaited(queue.add(() async {
    await asyncMessage("Message 2");
  }).catchError((e) => print("Message 2 error: $e")));

  queue.cancel();

  unawaited(queue
      .add(() async {
        await asyncMessage("Message 3");
        print("awaited message");
        // throw Exception("Error");
      })
      .then((result) => print("Message 3 complete"))
      .catchError((e) => print("Message 3 error: $e")));

  unawaited(queue
      .add(() async => asyncMessage("Message 4"))
      .then((result) => print("Message 4 complete"))
      .catchError((e) => print("Message 3 error: $e")));
}

void unawaited(Future<void> future) {}

Error Log:

image

@zeqinjie zeqinjie closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant